class Login extends UserAccessBase {
    constructor() {
        super()
        this.formEl = document.querySelector('.login-form')
        this.loginBtn = document.querySelector('#btn-login')
    }

    bindEvents() {
        this.seeBtn.addEventListener('click', () => {
            if (this.passwordInp.type === 'password') {
                this.passwordInp.type = 'input'
            } else if (this.passwordInp.type === 'text') {
                this.passwordInp.type = 'password'
            }
        })
        this.loginBtn.addEventListener('click', async () => {
            const data = serialize(this.formEl, { hash: true, empty: true })
            if (!data.username || !data.password) {
                return this.toast.show('用户名或者密码为空！')
            }
            if (data.username.length < 8 || data.username.length > 30) {
                return this.toast.show('用户名长度应在8-30位')
            }
            if (data.password.length < 6 || data.password.length > 30) {
                return this.toast.show('密码长度应在6-30位')
            }
            const res = await this.dataServes.login(data)
            this.toast.show(res.data.message)
            localStorage.setItem('userInfo', JSON.stringify(res.data.data))
            setTimeout(() => {
                location.href = './index.html'
            }, 2000);
        })
    }
}

const loginObj = new Login()
loginObj.init()